"""Lead contact repository implementation (Synchronous)."""

from __future__ import annotations

from sqlalchemy.orm import Session

from ..models.lead_contact import LeadContact
from .base import Repository
from ..schemas.lead_contact import LeadContactCreate, LeadContactUpdate


class LeadContactRepository(Repository[LeadContact, LeadContactCreate, LeadContactUpdate]):
    """Repository for LeadContact operations (Synchronous)."""

    def __init__(self, session: Session) -> None:
        super().__init__(LeadContact, session)

    def get_by_lead(self, lead_id: int) -> list[LeadContact]:
        """Get all contacts for a specific lead."""
        return (
            self.session.query(LeadContact)
            .filter(LeadContact.lead_id == lead_id)
            .order_by(LeadContact.id)
            .all()
        )

    def get_primary_contact(self, lead_id: int) -> LeadContact | None:
        """Get the first contact for a lead (assumed primary)."""
        return (
            self.session.query(LeadContact)
            .filter(LeadContact.lead_id == lead_id)
            .order_by(LeadContact.id)
            .first()
        )
